


export default {
  components: {
    AgForm: () => import("@/components/AgForm/AgForm.vue"),
    AgModalForm: () => import("@/components/AgForm/AgModalForm.vue")
  },
  methods: {
    tableInit(table = {}) {
      const _table = {
        data: [],
        columns: [],
        selectedRows: [],
        scroll: { x: 1000, y: 500 },
      }
      const _rowSelection = {
        columnWidth: 50,
        selectedRowKeys: [],
        // onSelect: (record, selected, selectedRows) => {
        //   _table.selectedRows = selectedRows;
        // },
        // onSelectAll: (selected, selectedRows, changeRows) => {
        //   _table.selectedRows = selectedRows;
        // },
        onChange: (keys, rows) => {
          console.log(keys);
          _rowSelection.selectedRowKeys = keys;
          _table.selectedRows = rows;
        },
        fixed:true
      }

      const _page = {
        // current: 1,
        // defaultPageSize: 20,
        // total: 0,
        // onChange: function (v) {
        //   _table.page.current = v;
        // }
        defaultPageSize: 20,
        current: 1,
        pageSize: 20,
        total: 0,
        showTotal: total => {
          return (
            <div>
              共 {total} 条数据，每页
              <a-input-number
                value={_page.pageSize}
                min={1}
                max={500}
                onPressEnter={e => _page.changePageSize(e)}
              />
              条
            </div>
          );
        },
        showQuickJumper: true,
        showLessItems: true,
        changePageSize: (e) => {
          const value = e.target.value;
          console.log(e, value);
          Object.assign(_page, {
            pageSize: Number.parseInt(value),
            current:1
          });
          console.log("----------------", table.onTablechage);
          table.onTablechage && table.onTablechage();
        },

      };

      const _onTableChange = (pagination, filters, sorter) => {
        Object.assign(_page, {
          current: pagination.current,
          pageSize: pagination.pageSize
        });
        table.onTablechage && table.onTablechage();
      };

      _table.edit = (callback) => {
        if (_table.selectedRows.length != 1) {
          this.$message.warning("请先选择一条要修改的数据");
          return;
        }
        callback && callback()
      }

      _table.remove = (callback) => {
        if (_table.selectedRows.length < 1) {
          this.$message.warning("请先选择要删除的数据");
          return;
        }
        this.$confirm({
          title: '确认',
          content: <span>您确定要{<span style='color:red;'>删除</span>}该记录吗？</span>,
          onOk() {
            callback && callback()
          },
          onCancel() {},
        });
        
      }

      // _table.resize = (callback) => {
      //   const name = '.a-base-table'
      //   const table = document.querySelector(name)
      //   const tableHead = document.querySelector(`${name} .ant-table-thead`)
      //   console.log(table.clientHeight, tableHead.clientHeight)
      // }
      // _table.resize()
      table.rowSelection = Object.assign(_rowSelection, table.rowSelection = {})
      table.page = Object.assign(_page, table.page = {})
      table.tableChange = Object.assign(_onTableChange, table.tableChange = {})
      return Object.assign(_table, table)
    },
    
  },
  created() {
  }
}